package date0604_2_Multiton;

/**
 * "饿汉式"多例 ( Multiton ) 
 * 1、将所有构造方法私有化
 * 2、使用 类变量 将 有限的几个实例缓存起来
 * 3、提供 类方法 用以获取指定的 实例
 */
public class Season {

	private int index; // 第几个季度
	private String name; // 季度名称
	private String description; // 季度描述
	
	public static final Season SPRING = new Season( 1 , "春" , "春暖花开" ) ;
	public static final Season SUMMER = new Season( 2 , "夏" , "炎炎夏日" ) ;
	public static final Season AUTUMN = new Season( 3 , "秋" , "秋高气爽" ) ;
	// Eclipse 快捷键: ctrl + shift + y 变小写 ,  ctrl + shift + x 变大写
	public static final Season WINTER = new Season( 4 , "冬" , "银装素裹" ) ;

	private Season(int index, String name, String description) {
		super();
		this.index = index;
		this.name = name;
		this.description = description;
	}

	
	// 静态工厂方法 ( static factory method )
	public static Season of( int index ){
		switch ( index ) {
			case 1: return SPRING ;
			case 2: return SUMMER ;
			case 3: return AUTUMN ;
			case 4: return WINTER ;
			default: return null ;
		}
	}
	
	// 静态工厂方法 ( static factory method )
	public static Season of( String name ){
		// JDK 1.7 开始 支持在 switch 中使用 String
		switch ( name ) {
			case "春" : return SPRING ;
			case "夏": return SUMMER ;
			case "秋": return AUTUMN ;
			case "冬": return WINTER ;
			default: return null ;
		}
	}
	
	public int getIndex() {
		return index;
	}
	

	public String getName() {
		return name;
	}
	

	public String getDescription() {
		return description;
	}

}
